import pandas as pd
from pandas.api.types import is_numeric_dtype

if __name__=="__main__":
    names=['一号泵', '二号泵', '三号泵', '四号泵']
    dir="../data/"
    allFields=[]
    for name in names:
        path = dir+name+".csv"
        data = pd.read_csv(path, index_col=0, encoding="utf-8")
        data = data.dropna(axis=1, how='all')
        fields = list(data.columns)
        ls=[]
        for field in fields:
            if is_numeric_dtype(data[field]) and \
                    "累积" not in field and \
                    "累计" not in field and \
                    field!="label":
                ls.append(field)
        allFields.append(ls)
    commonFields = set(allFields[0])
    for fields in allFields:
        commonFields=commonFields.intersection(set(fields))
    print("共有数据列",list(commonFields))
    for idx,fields in enumerate(allFields):
        extra=list(set(fields)-commonFields)
        if len(extra)!=0:
            print('第%d个文件的额外字段' % (idx + 1))
            print(extra)
    name="一号泵"
    path='./data/{}.csv'.format(name)
    print(path+"，统计量")
    data = pd.read_csv(path, index_col=0, encoding="utf-8")
    data=data[list(commonFields)]
    desc=data.describe()
    desc.to_csv("{}统计量.csv".format(name))